package com.wutuo.aggragation.report.component;

import java.text.ParseException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang3.tuple.ImmutablePair;
import org.apache.commons.lang3.tuple.Pair;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.wutuo.aggragation.report.response.ListMonthSignDataItem;
import com.wutuo.aggragation.report.response.ListMonthSignTaskItem;
import com.wutuo.aggragation.report.response.ListMonthTaskDataItem;
import com.wutuo.aggragation.report.response.ListMonthTaskDetailItem;
import com.wutuo.aggragation.report.vo.TaskTypeMonthSignNumber;

import cn.apestar.core.framework.exception.BusinessException;
import cn.apestar.core.utils.DateEnum;
import cn.apestar.core.utils.DateUtils;

/**
 * 标题、简要说明. <br>
 * 类详细说明.
 * <p/>
 * Copyright: Copyright (c) 2016年4月23日 上午8:21:41
 * <p/>
 * Company: 网龙公司
 * <p/>
 * @author Shunqin.Chen
 * @version 1.0.0
 */
public class SignReportDataConvert {

    private static final Logger LOGGER = LoggerFactory.getLogger(SignReportDataConvert.class);

    public static List<ListMonthSignDataItem> covertToListMonthSignData() {
        List<ListMonthSignDataItem> result = new ArrayList<>();
        for (int i = 1; i < 9; i++) {
            ListMonthSignDataItem item = new ListMonthSignDataItem();
            item.setMonth("2016" + "" + "0" + i);
            item.setTotal(10);

            List<ListMonthSignTaskItem> taskData = new ArrayList<>();
            for (int j = 1; j < 5; j++) {
                ListMonthSignTaskItem subItem = new ListMonthSignTaskItem();
                subItem.setTypeName("点名任务" + j);
                subItem.setType("wutuo");
                subItem.setCount(10);
                taskData.add(subItem);
            }

            item.setDetail(taskData);
            result.add(item);
        }
        return result;
    }

    public static List<ListMonthTaskDataItem> convertToListMonthTaskDataItems() {
        List<ListMonthTaskDataItem> result = new ArrayList<>();
        for (int i = 0; i < 10; i++) {
            ListMonthTaskDataItem item = new ListMonthTaskDataItem();
            item.setChildId(Long.valueOf(i));
            item.setChildName("小孩" + i);
            item.setImg("");
            if (i % 2 == 0) {
                item.setSex("male");
            } else {
                item.setSex("female");
            }

            item.setYear("2016");
            item.setSignNum(i * 5);
            result.add(item);
        }
        return result;

    }

    public static List<ListMonthTaskDetailItem> convertToTaskDetailItems(String month) {
        List<ListMonthTaskDetailItem> result = new ArrayList<>();
        Date date;
        try {
            date = DateUtils.parseDate(month + "01", "yyyyMMdd");
        } catch (ParseException e) {
            throw new BusinessException("date.convert.fail");
        }
        for (int i = 1; i < 20; i++) {
            ListMonthTaskDetailItem item = new ListMonthTaskDetailItem();
            date = DateUtils.addDays(date, 1);
            item.setDay(DateUtils.formatDate(date, DateEnum.YYYYMMDD));
            result.add(item);
        }
        return result;
    }

    public static Map<Pair<String, String>, TaskTypeMonthSignNumber> convertTaskTypeMonthSignNumberToMap(List<TaskTypeMonthSignNumber> list) {
        if (CollectionUtils.isEmpty(list)) {
            return Collections.emptyMap();
        }
        Map<Pair<String, String>, TaskTypeMonthSignNumber> map = new HashMap<>();
        for (TaskTypeMonthSignNumber item : list) {
            Pair<String, String> key = new ImmutablePair<>(item.getTaskType(), item.getTaskMonth());
            map.put(key, item);
        }

        return map;
    }
}
